package com.ruoyi.mongo.cet4.service.impl;

import com.ruoyi.mongo.cet4.Entity4;
import com.ruoyi.mongo.cet4.EntityNet4;
import com.ruoyi.mongo.cet4.repository.SecondaryNetRepository;
import com.ruoyi.mongo.cet4.service.EntityNetInterface;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class EntityNetService implements EntityNetInterface {

    private final SecondaryNetRepository netRepository;

    public EntityNetService(SecondaryNetRepository netRepository) {
        this.netRepository = netRepository;
    }

    @Override
    public void insertNetDataByUser(Entity4 entity, Long userId) {
        if (entity.getWordMore() != null && !entity.getWordMore().isEmpty()){
            log.info("保存网络资源:{},时间:{}", entity.getName(), DateUtils.getLocalTime());
            EntityNet4 entityNet4 = new EntityNet4();
            BeanUtils.copyBeanProp(entityNet4, entity);
            entityNet4.setUserId(userId);
            netRepository.save(entityNet4);
        }
    }
}
